package com.yunji.web.product;

import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.product.business.ProductAgentBusiness;
import com.yunji.product.domain.ProductAgentDO;
import com.yunji.product.dto.ProductAccreditDTO;
import com.yunji.product.dto.ProductAgentDTO;
import com.yunji.product.params.PermissionsParam;
import com.yunji.product.vo.ProductAccreditVO;
import com.yunji.product.vo.ProductCompareVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Package com.yunji.web.product
 * FileName:	ProductAgentController.java
 * Copyright:	Copyright © 2024 云集互联 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-04-01 09:31:06
 * Description:
 * 商品授权代理交互
 * Modification History:
 * Author					Date						Version			Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-01 09:31:06			1.0				1.0 Version
 */
@Api(tags = "管理端-商品授权代理")
@RestController
@RequestMapping("product/agent")
public class ProductAgentController extends BaseController {
    @Resource
    ProductAgentBusiness business;

    @ApiOperation("修改授权商品信息")
    @PutMapping
    public Response<String> update(@RequestBody ProductAgentDTO dto) {
        business.update(dto);
        return ResponseHelper.success("修改成功");
    }

    @ApiOperation("修改代理商初始价格")
//    @PreAuthorize("@ss.hasPermi('container:product:agentPrice')")
    @PutMapping("/agentPrice")
    public Response<String> agentPrice(@RequestBody ProductAgentDTO dto) {
        business.agentPrice(dto);
        return ResponseHelper.success("修改成功");
    }

    @ApiOperation("获取授权商品详细信息")
    @GetMapping(value = "{productId}")
    public Response<ProductAgentDO> getInfo(@PathVariable("productId") Long productId) {
        return ResponseHelper.success(business.selectCurrent(productId));
    }

    @ApiOperation("校验商品授权")
//    @PreAuthorize("@ss.hasPermi('container:product:authorize')")
    @PostMapping(value = "productAccredit")
    public Response<List<ProductAccreditVO>> productAccredit(@RequestBody @Valid ProductAccreditDTO dto) {
        return ResponseHelper.successWithPage(business.productAccredit(dto));
    }

    @ApiOperation("商品权限对比列表")
    @GetMapping(value = "comparePermissions")
    public Response<List<ProductCompareVO>> comparePermissions(PermissionsParam param) {
        List<ProductCompareVO> list = business.comparePermissions(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("货柜商品权限对比结果")
    @PostMapping("compareResult")
    public Response<Boolean> compareResult(@RequestBody PermissionsParam param) {
        return ResponseHelper.success(business.compareResult(param));
    }

    @ApiOperation("修改商品授权")
    @PostMapping("changeAccredit")
    public Response<String> changeAccredit(@RequestBody ProductAccreditDTO dto) {
        business.changeAccredit(dto);
        return ResponseHelper.success("修改成功");
    }

}
